﻿namespace WMS6.SQLServerDAL
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.Common;
    using System.Data.SqlClient;
    using WMS6.Common;
    using WMS6.DataEntity;
    using WMS6.DBUtility;
    using WMS6.IDAL;
    using WMS6.QueryEntity;

    public class PackDA : IPackDA
    {
        private string CASE_CNT = "@CASE_CNT";
        private string CREATED_BY = "@CREATED_BY";
        private string CUBE = "@CUBE";
        private string CUBE_UOM1 = "@CUBE_UOM1";
        private string CUBE_UOM2 = "@CUBE_UOM2";
        private string CUBE_UOM3 = "@CUBE_UOM3";
        private string CUBE_UOM4 = "@CUBE_UOM4";
        private string DESCRIPTION = "@DESCRIPTION";
        private string GROSS_WGT = "@GROSS_WGT";
        private string HEIGHT_UOM1 = "@HEIGHT_UOM1";
        private string HEIGHT_UOM2 = "@HEIGHT_UOM2";
        private string HEIGHT_UOM3 = "@HEIGHT_UOM3";
        private string HEIGHT_UOM4 = "@HEIGHT_UOM4";
        private string HEIGHT_UOM8 = "@HEIGHT_UOM8";
        private string HEIGHT_UOM9 = "@HEIGHT_UOM9";
        private string INNER_PACK = "@INNER_PACK";
        private string IS_ACTIVE = "@IS_ACTIVE";
        private string IS_CARTONIZE_UOM1 = "@IS_CARTONIZE_UOM1";
        private string IS_CARTONIZE_UOM2 = "@IS_CARTONIZE_UOM2";
        private string IS_CARTONIZE_UOM3 = "@IS_CARTONIZE_UOM3";
        private string IS_CARTONIZE_UOM4 = "@IS_CARTONIZE_UOM4";
        private string IS_CARTONIZE_UOM8 = "@IS_CARTONIZE_UOM8";
        private string IS_CARTONIZE_UOM9 = "@IS_CARTONIZE_UOM9";
        private string IS_IN_LABEL_UOM1 = "@IS_IN_LABEL_UOM1";
        private string IS_IN_LABEL_UOM2 = "@IS_IN_LABEL_UOM2";
        private string IS_IN_LABEL_UOM3 = "@IS_IN_LABEL_UOM3";
        private string IS_IN_LABEL_UOM4 = "@IS_IN_LABEL_UOM4";
        private string IS_IN_LABEL_UOM8 = "@IS_IN_LABEL_UOM8";
        private string IS_IN_LABEL_UOM9 = "@IS_IN_LABEL_UOM9";
        private string IS_OUT_LABEL_UOM1 = "@IS_OUT_LABEL_UOM1";
        private string IS_OUT_LABEL_UOM2 = "@IS_OUT_LABEL_UOM2";
        private string IS_OUT_LABEL_UOM3 = "@IS_OUT_LABEL_UOM3";
        private string IS_OUT_LABEL_UOM4 = "@IS_OUT_LABEL_UOM4";
        private string IS_OUT_LABEL_UOM8 = "@IS_OUT_LABEL_UOM8";
        private string IS_OUT_LABEL_UOM9 = "@IS_OUT_LABEL_UOM9";
        private string IS_REPLENISH_UOM1 = "@IS_REPLENISH_UOM1";
        private string IS_REPLENISH_UOM2 = "@IS_REPLENISH_UOM2";
        private string IS_REPLENISH_UOM3 = "@IS_REPLENISH_UOM3";
        private string IS_REPLENISH_UOM4 = "@IS_REPLENISH_UOM4";
        private string IS_REPLENISH_UOM8 = "@IS_REPLENISH_UOM8";
        private string IS_REPLENISH_UOM9 = "@IS_REPLENISH_UOM9";
        private string LENGTH_UOM1 = "@LENGTH_UOM1";
        private string LENGTH_UOM2 = "@LENGTH_UOM2";
        private string LENGTH_UOM3 = "@LENGTH_UOM3";
        private string LENGTH_UOM4 = "@LENGTH_UOM4";
        private string LENGTH_UOM8 = "@LENGTH_UOM8";
        private string LENGTH_UOM9 = "@LENGTH_UOM9";
        private string NET_WGT = "@NET_WGT";
        private string OTHER_UNIT1 = "@OTHER_UNIT1";
        private string OTHER_UNIT2 = "@OTHER_UNIT2";
        private string PACK_ID = "@PACK_ID";
        private string PACK_UOM1 = "@PACK_UOM1";
        private string PACK_UOM2 = "@PACK_UOM2";
        private string PACK_UOM3 = "@PACK_UOM3";
        private string PACK_UOM4 = "@PACK_UOM4";
        private string PACK_UOM5 = "@PACK_UOM5";
        private string PACK_UOM6 = "@PACK_UOM6";
        private string PACK_UOM7 = "@PACK_UOM7";
        private string PACK_UOM8 = "@PACK_UOM8";
        private string PACK_UOM9 = "@PACK_UOM9";
        private string PALLET = "@PALLET";
        private string PALLET_HI = "@PALLET_HI";
        private string PALLET_TI = "@PALLET_TI";
        private string PALLET_WOOD_HEIGHT = "@PALLET_WOOD_HEIGHT";
        private string PALLET_WOOD_LENGTH = "@PALLET_WOOD_LENGTH";
        private string PALLET_WOOD_WIDTH = "@PALLET_WOOD_WIDTH";
        private string QTY = "@QTY";
        private string SQL_CHECK_PACK_ID_UNIQUE = " SELECT COUNT(1) FROM @_@PACK WHERE PACK_ID = @PACK_ID ";
        private string SQL_DELETE_PACK = " DELETE FROM @_@PACK WHERE PACK_ID = @PACK_ID AND SYSTEM_CREATED = 'N' ";
        private string SQL_INSERT_PACK = " INSERT INTO @_@PACK ( WH_ID, PACK_ID, DESCRIPTION, PACK_UOM1, QTY, LENGTH_UOM1, WIDTH_UOM1, HEIGHT_UOM1, CUBE_UOM1, PACK_UOM2, INNER_PACK, LENGTH_UOM2, WIDTH_UOM2, HEIGHT_UOM2, CUBE_UOM2, PACK_UOM3, CASE_CNT, LENGTH_UOM3, WIDTH_UOM3, HEIGHT_UOM3, CUBE_UOM3, PACK_UOM4, PALLET, LENGTH_UOM4, WIDTH_UOM4, HEIGHT_UOM4, CUBE_UOM4, PALLET_WOOD_LENGTH, PALLET_WOOD_WIDTH, PALLET_WOOD_HEIGHT, PALLET_TI, PALLET_HI, PACK_UOM5, CUBE, PACK_UOM6, GROSS_WGT, PACK_UOM7, NET_WGT, PACK_UOM8, OTHER_UNIT1, LENGTH_UOM8, WIDTH_UOM8, HEIGHT_UOM8, PACK_UOM9, OTHER_UNIT2, LENGTH_UOM9, WIDTH_UOM9, HEIGHT_UOM9, IS_CARTONIZE_UOM1, IS_CARTONIZE_UOM2, IS_CARTONIZE_UOM3, IS_CARTONIZE_UOM4, IS_CARTONIZE_UOM8, IS_CARTONIZE_UOM9, IS_REPLENISH_UOM1, IS_REPLENISH_UOM2, IS_REPLENISH_UOM3, IS_REPLENISH_UOM4, IS_REPLENISH_UOM8, IS_REPLENISH_UOM9, IS_IN_LABEL_UOM1, IS_IN_LABEL_UOM2, IS_IN_LABEL_UOM3, IS_IN_LABEL_UOM4, IS_IN_LABEL_UOM8, IS_IN_LABEL_UOM9, IS_OUT_LABEL_UOM1, IS_OUT_LABEL_UOM2, IS_OUT_LABEL_UOM3, IS_OUT_LABEL_UOM4, IS_OUT_LABEL_UOM8, IS_OUT_LABEL_UOM9, IS_ACTIVE, SYSTEM_CREATED, CREATED_BY, CREATED_DATE, UPDATED_BY, UPDATED_DATE) VALUES ( @WH_ID, @PACK_ID, @DESCRIPTION, @PACK_UOM1, @QTY, @LENGTH_UOM1, @WIDTH_UOM1, @HEIGHT_UOM1, @CUBE_UOM1, @PACK_UOM2, @INNER_PACK, @LENGTH_UOM2, @WIDTH_UOM2, @HEIGHT_UOM2, @CUBE_UOM2, @PACK_UOM3, @CASE_CNT, @LENGTH_UOM3, @WIDTH_UOM3, @HEIGHT_UOM3, @CUBE_UOM3, @PACK_UOM4, @PALLET, @LENGTH_UOM4, @WIDTH_UOM4, @HEIGHT_UOM4, @CUBE_UOM4, @PALLET_WOOD_LENGTH, @PALLET_WOOD_WIDTH, @PALLET_WOOD_HEIGHT, @PALLET_TI, @PALLET_HI, @PACK_UOM5, @CUBE, @PACK_UOM6, @GROSS_WGT, @PACK_UOM7, @NET_WGT, @PACK_UOM8, @OTHER_UNIT1, @LENGTH_UOM8, @WIDTH_UOM8, @HEIGHT_UOM8, @PACK_UOM9, @OTHER_UNIT2, @LENGTH_UOM9, @WIDTH_UOM9, @HEIGHT_UOM9, @IS_CARTONIZE_UOM1, @IS_CARTONIZE_UOM2, @IS_CARTONIZE_UOM3, @IS_CARTONIZE_UOM4, @IS_CARTONIZE_UOM8, @IS_CARTONIZE_UOM9, @IS_REPLENISH_UOM1, @IS_REPLENISH_UOM2, @IS_REPLENISH_UOM3, @IS_REPLENISH_UOM4, @IS_REPLENISH_UOM8, @IS_REPLENISH_UOM9, @IS_IN_LABEL_UOM1, @IS_IN_LABEL_UOM2, @IS_IN_LABEL_UOM3, @IS_IN_LABEL_UOM4, @IS_IN_LABEL_UOM8, @IS_IN_LABEL_UOM9, @IS_OUT_LABEL_UOM1, @IS_OUT_LABEL_UOM2, @IS_OUT_LABEL_UOM3, @IS_OUT_LABEL_UOM4, @IS_OUT_LABEL_UOM8, @IS_OUT_LABEL_UOM9, @IS_ACTIVE, @SYSTEM_CREATED, @CREATED_BY, GETDATE(), @UPDATED_BY, GETDATE() )  ";
        private string SQL_SELECT_ALL_PACK = " SELECT  ROWID, WH_ID, PACK_ID, DESCRIPTION, PACK_UOM1, QTY, LENGTH_UOM1, WIDTH_UOM1, HEIGHT_UOM1, CUBE_UOM1, PACK_UOM2, INNER_PACK, LENGTH_UOM2, WIDTH_UOM2, HEIGHT_UOM2, CUBE_UOM2, PACK_UOM3, CASE_CNT, LENGTH_UOM3, WIDTH_UOM3, HEIGHT_UOM3, CUBE_UOM3, PACK_UOM4, PALLET, LENGTH_UOM4, WIDTH_UOM4, HEIGHT_UOM4, CUBE_UOM4, PALLET_WOOD_LENGTH, PALLET_WOOD_WIDTH, PALLET_WOOD_HEIGHT, PALLET_TI, PALLET_HI, PACK_UOM5, CUBE, PACK_UOM6, GROSS_WGT, PACK_UOM7, NET_WGT, PACK_UOM8, OTHER_UNIT1, LENGTH_UOM8, WIDTH_UOM8, HEIGHT_UOM8, PACK_UOM9, OTHER_UNIT2, LENGTH_UOM9, WIDTH_UOM9, HEIGHT_UOM9, IS_CARTONIZE_UOM1, IS_CARTONIZE_UOM2, IS_CARTONIZE_UOM3, IS_CARTONIZE_UOM4, IS_CARTONIZE_UOM8, IS_CARTONIZE_UOM9, IS_REPLENISH_UOM1, IS_REPLENISH_UOM2, IS_REPLENISH_UOM3, IS_REPLENISH_UOM4, IS_REPLENISH_UOM8, IS_REPLENISH_UOM9, IS_IN_LABEL_UOM1, IS_IN_LABEL_UOM2, IS_IN_LABEL_UOM3, IS_IN_LABEL_UOM4, IS_IN_LABEL_UOM8, IS_IN_LABEL_UOM9, IS_OUT_LABEL_UOM1, IS_OUT_LABEL_UOM2, IS_OUT_LABEL_UOM3, IS_OUT_LABEL_UOM4, IS_OUT_LABEL_UOM8, IS_OUT_LABEL_UOM9, IS_ACTIVE, SYSTEM_CREATED, TS, CREATED_BY, CREATED_DATE, UPDATED_BY, UPDATED_DATE  FROM  @_@PACK ";
        private string SQL_UPDATE_PACK = " UPDATE @_@PACK SET WH_ID = @WH_ID, DESCRIPTION = @DESCRIPTION, PACK_UOM1 = @PACK_UOM1, QTY = @QTY, LENGTH_UOM1 = @LENGTH_UOM1, WIDTH_UOM1 = @WIDTH_UOM1, HEIGHT_UOM1 = @HEIGHT_UOM1, CUBE_UOM1 = @CUBE_UOM1, PACK_UOM2 = @PACK_UOM2, INNER_PACK = @INNER_PACK, LENGTH_UOM2 = @LENGTH_UOM2, WIDTH_UOM2 = @WIDTH_UOM2, HEIGHT_UOM2 = @HEIGHT_UOM2, CUBE_UOM2 = @CUBE_UOM2, PACK_UOM3 = @PACK_UOM3, CASE_CNT = @CASE_CNT, LENGTH_UOM3 = @LENGTH_UOM3, WIDTH_UOM3 = @WIDTH_UOM3, HEIGHT_UOM3 = @HEIGHT_UOM3, CUBE_UOM3 = @CUBE_UOM3, PACK_UOM4 = @PACK_UOM4, PALLET = @PALLET, LENGTH_UOM4 = @LENGTH_UOM4, WIDTH_UOM4 = @WIDTH_UOM4, HEIGHT_UOM4 = @HEIGHT_UOM4, CUBE_UOM4 = @CUBE_UOM4, PALLET_WOOD_LENGTH = @PALLET_WOOD_LENGTH, PALLET_WOOD_WIDTH = @PALLET_WOOD_WIDTH, PALLET_WOOD_HEIGHT = @PALLET_WOOD_HEIGHT, PALLET_TI = @PALLET_TI, PALLET_HI = @PALLET_HI, PACK_UOM5 = @PACK_UOM5, CUBE = @CUBE, PACK_UOM6 = @PACK_UOM6, GROSS_WGT = @GROSS_WGT, PACK_UOM7 = @PACK_UOM7, NET_WGT = @NET_WGT, PACK_UOM8 = @PACK_UOM8, OTHER_UNIT1 = @OTHER_UNIT1, LENGTH_UOM8 = @LENGTH_UOM8, WIDTH_UOM8 = @WIDTH_UOM8, HEIGHT_UOM8 = @HEIGHT_UOM8, PACK_UOM9 = @PACK_UOM9, OTHER_UNIT2 = @OTHER_UNIT2, LENGTH_UOM9 = @LENGTH_UOM9, WIDTH_UOM9 = @WIDTH_UOM9, HEIGHT_UOM9 = @HEIGHT_UOM9, IS_CARTONIZE_UOM1 = @IS_CARTONIZE_UOM1, IS_CARTONIZE_UOM2 = @IS_CARTONIZE_UOM2, IS_CARTONIZE_UOM3 = @IS_CARTONIZE_UOM3, IS_CARTONIZE_UOM4 = @IS_CARTONIZE_UOM4, IS_CARTONIZE_UOM8 = @IS_CARTONIZE_UOM8, IS_CARTONIZE_UOM9 = @IS_CARTONIZE_UOM9, IS_REPLENISH_UOM1 = @IS_REPLENISH_UOM1, IS_REPLENISH_UOM2 = @IS_REPLENISH_UOM2, IS_REPLENISH_UOM3 = @IS_REPLENISH_UOM3, IS_REPLENISH_UOM4 = @IS_REPLENISH_UOM4, IS_REPLENISH_UOM8 = @IS_REPLENISH_UOM8, IS_REPLENISH_UOM9 = @IS_REPLENISH_UOM9, IS_IN_LABEL_UOM1 = @IS_IN_LABEL_UOM1, IS_IN_LABEL_UOM2 = @IS_IN_LABEL_UOM2, IS_IN_LABEL_UOM3 = @IS_IN_LABEL_UOM3, IS_IN_LABEL_UOM4 = @IS_IN_LABEL_UOM4, IS_IN_LABEL_UOM8 = @IS_IN_LABEL_UOM8, IS_IN_LABEL_UOM9 = @IS_IN_LABEL_UOM9, IS_OUT_LABEL_UOM1 = @IS_OUT_LABEL_UOM1, IS_OUT_LABEL_UOM2 = @IS_OUT_LABEL_UOM2, IS_OUT_LABEL_UOM3 = @IS_OUT_LABEL_UOM3, IS_OUT_LABEL_UOM4 = @IS_OUT_LABEL_UOM4, IS_OUT_LABEL_UOM8 = @IS_OUT_LABEL_UOM8, IS_OUT_LABEL_UOM9 = @IS_OUT_LABEL_UOM9, IS_ACTIVE = @IS_ACTIVE, SYSTEM_CREATED = @SYSTEM_CREATED, UPDATED_BY = @UPDATED_BY, UPDATED_DATE = GETDATE() WHERE PACK_ID = @PACK_ID  ";
        private string SYSTEM_CREATED = "@SYSTEM_CREATED";
        private string TS = "@TS";
        private string UPDATED_BY = "@UPDATED_BY";
        private string WH_ID = "@WH_ID";
        private string WIDTH_UOM1 = "@WIDTH_UOM1";
        private string WIDTH_UOM2 = "@WIDTH_UOM2";
        private string WIDTH_UOM3 = "@WIDTH_UOM3";
        private string WIDTH_UOM4 = "@WIDTH_UOM4";
        private string WIDTH_UOM8 = "@WIDTH_UOM8";
        private string WIDTH_UOM9 = "@WIDTH_UOM9";

        public bool CheckPackIDUnique(string packID, string whLoginID)
        {
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@PACK_ID", packID) };
            return (DBHelper.ExecuteScalar(CommandType.Text, this.SQL_CHECK_PACK_ID_UNIQUE.Replace("@_@", whLoginID), paras).ToString() == "1");
        }

        public bool CheckPackIDUnique(DataBase dataBase, DbTransaction tran, string packID, string whLoginID)
        {
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@PACK_ID", packID) };
            return (dataBase.ExecuteScalar(tran, CommandType.Text, this.SQL_CHECK_PACK_ID_UNIQUE.Replace("@_@", whLoginID), paras).ToString() == "1");
        }

        public int DeletePack(List<string> packID, List<string> whLoginID)
        {
            int result = 0;
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    for (int j = 0; j < packID.Count; j++)
                    {
                        SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@PACK_ID", packID[j]) };
                        result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_DELETE_PACK.Replace("@_@", whLoginID[i]), paras);
                    }
                }
                tran.Commit();
            }
            catch (SqlException sqlEx)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return result;
        }

        public int DeletePack(DataBase dataBase, DbTransaction tran, List<string> packID, List<string> whLoginID)
        {
            int result = 0;
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    for (int j = 0; j < packID.Count; j++)
                    {
                        SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@PACK_ID", packID[j]) };
                        result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_DELETE_PACK.Replace("@_@", whLoginID[i]), paras);
                    }
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }

        public DataSet GetAllPack(string whLoginID)
        {
            string sql = this.SQL_SELECT_ALL_PACK.Replace("@_@", whLoginID);
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetAllPack(DataBase dataBase, DbTransaction tran, string whLoginID)
        {
            string sql = this.SQL_SELECT_ALL_PACK.Replace("@_@", whLoginID);
            return dataBase.ExecuteDataSet(tran, CommandType.Text, sql);
        }

        public PackInfo GetPackByID(string packID, string whLoginID)
        {
            string sql = this.SQL_SELECT_ALL_PACK.Replace("@_@", whLoginID) + " WHERE PACK_ID = @PACK_ID  ";
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@PACK_ID", packID) };
            PackInfo packInfo = null;
            using (IDataReader reader = DBHelper.ExecuteReader(CommandType.Text, sql, paras))
            {
                if (reader.Read())
                {
                    packInfo = new PackInfo((reader["ROWID"].ToString() != "") ? int.Parse(reader["ROWID"].ToString()) : 0, reader["WH_ID"].ToString(), reader["PACK_ID"].ToString(), reader["DESCRIPTION"].ToString(), reader["PACK_UOM1"].ToString(), (reader["QTY"].ToString() != "") ? float.Parse(reader["QTY"].ToString()) : 0f, (reader["LENGTH_UOM1"].ToString() != "") ? float.Parse(reader["LENGTH_UOM1"].ToString()) : 0f, (reader["WIDTH_UOM1"].ToString() != "") ? float.Parse(reader["WIDTH_UOM1"].ToString()) : 0f, (reader["HEIGHT_UOM1"].ToString() != "") ? float.Parse(reader["HEIGHT_UOM1"].ToString()) : 0f, (reader["CUBE_UOM1"].ToString() != "") ? float.Parse(reader["CUBE_UOM1"].ToString()) : 0f, reader["PACK_UOM2"].ToString(), (reader["INNER_PACK"].ToString() != "") ? float.Parse(reader["INNER_PACK"].ToString()) : 0f, (reader["LENGTH_UOM2"].ToString() != "") ? float.Parse(reader["LENGTH_UOM2"].ToString()) : 0f, (reader["WIDTH_UOM2"].ToString() != "") ? float.Parse(reader["WIDTH_UOM2"].ToString()) : 0f, (reader["HEIGHT_UOM2"].ToString() != "") ? float.Parse(reader["HEIGHT_UOM2"].ToString()) : 0f, (reader["CUBE_UOM2"].ToString() != "") ? float.Parse(reader["CUBE_UOM2"].ToString()) : 0f, reader["PACK_UOM3"].ToString(), (reader["CASE_CNT"].ToString() != "") ? float.Parse(reader["CASE_CNT"].ToString()) : 0f, (reader["LENGTH_UOM3"].ToString() != "") ? float.Parse(reader["LENGTH_UOM3"].ToString()) : 0f, (reader["WIDTH_UOM3"].ToString() != "") ? float.Parse(reader["WIDTH_UOM3"].ToString()) : 0f, (reader["HEIGHT_UOM3"].ToString() != "") ? float.Parse(reader["HEIGHT_UOM3"].ToString()) : 0f, (reader["CUBE_UOM3"].ToString() != "") ? float.Parse(reader["CUBE_UOM3"].ToString()) : 0f, reader["PACK_UOM4"].ToString(), (reader["PALLET"].ToString() != "") ? float.Parse(reader["PALLET"].ToString()) : 0f, (reader["LENGTH_UOM4"].ToString() != "") ? float.Parse(reader["LENGTH_UOM4"].ToString()) : 0f, (reader["WIDTH_UOM4"].ToString() != "") ? float.Parse(reader["WIDTH_UOM4"].ToString()) : 0f, (reader["HEIGHT_UOM4"].ToString() != "") ? float.Parse(reader["HEIGHT_UOM4"].ToString()) : 0f, (reader["CUBE_UOM4"].ToString() != "") ? float.Parse(reader["CUBE_UOM4"].ToString()) : 0f, (reader["PALLET_WOOD_LENGTH"].ToString() != "") ? float.Parse(reader["PALLET_WOOD_LENGTH"].ToString()) : 0f, (reader["PALLET_WOOD_WIDTH"].ToString() != "") ? float.Parse(reader["PALLET_WOOD_WIDTH"].ToString()) : 0f, (reader["PALLET_WOOD_HEIGHT"].ToString() != "") ? float.Parse(reader["PALLET_WOOD_HEIGHT"].ToString()) : 0f, (reader["PALLET_TI"].ToString() != "") ? decimal.Parse(reader["PALLET_TI"].ToString()) : 0M, (reader["PALLET_HI"].ToString() != "") ? decimal.Parse(reader["PALLET_HI"].ToString()) : 0M, reader["PACK_UOM5"].ToString(), (reader["CUBE"].ToString() != "") ? float.Parse(reader["CUBE"].ToString()) : 0f, reader["PACK_UOM6"].ToString(), (reader["GROSS_WGT"].ToString() != "") ? float.Parse(reader["GROSS_WGT"].ToString()) : 0f, reader["PACK_UOM7"].ToString(), (reader["NET_WGT"].ToString() != "") ? float.Parse(reader["NET_WGT"].ToString()) : 0f, reader["PACK_UOM8"].ToString(), (reader["OTHER_UNIT1"].ToString() != "") ? float.Parse(reader["OTHER_UNIT1"].ToString()) : 0f, (reader["LENGTH_UOM8"].ToString() != "") ? float.Parse(reader["LENGTH_UOM8"].ToString()) : 0f, (reader["WIDTH_UOM8"].ToString() != "") ? float.Parse(reader["WIDTH_UOM8"].ToString()) : 0f, (reader["HEIGHT_UOM8"].ToString() != "") ? float.Parse(reader["HEIGHT_UOM8"].ToString()) : 0f, reader["PACK_UOM9"].ToString(), (reader["OTHER_UNIT2"].ToString() != "") ? float.Parse(reader["OTHER_UNIT2"].ToString()) : 0f, (reader["LENGTH_UOM9"].ToString() != "") ? float.Parse(reader["LENGTH_UOM9"].ToString()) : 0f, (reader["WIDTH_UOM9"].ToString() != "") ? float.Parse(reader["WIDTH_UOM9"].ToString()) : 0f, (reader["HEIGHT_UOM9"].ToString() != "") ? float.Parse(reader["HEIGHT_UOM9"].ToString()) : 0f, reader["IS_CARTONIZE_UOM1"].ToString(), reader["IS_CARTONIZE_UOM2"].ToString(), reader["IS_CARTONIZE_UOM3"].ToString(), reader["IS_CARTONIZE_UOM4"].ToString(), reader["IS_CARTONIZE_UOM8"].ToString(), reader["IS_CARTONIZE_UOM9"].ToString(), reader["IS_REPLENISH_UOM1"].ToString(), reader["IS_REPLENISH_UOM2"].ToString(), reader["IS_REPLENISH_UOM3"].ToString(), reader["IS_REPLENISH_UOM4"].ToString(), reader["IS_REPLENISH_UOM8"].ToString(), reader["IS_REPLENISH_UOM9"].ToString(), reader["IS_IN_LABEL_UOM1"].ToString(), reader["IS_IN_LABEL_UOM2"].ToString(), reader["IS_IN_LABEL_UOM3"].ToString(), reader["IS_IN_LABEL_UOM4"].ToString(), reader["IS_IN_LABEL_UOM8"].ToString(), reader["IS_IN_LABEL_UOM9"].ToString(), reader["IS_OUT_LABEL_UOM1"].ToString(), reader["IS_OUT_LABEL_UOM2"].ToString(), reader["IS_OUT_LABEL_UOM3"].ToString(), reader["IS_OUT_LABEL_UOM4"].ToString(), reader["IS_OUT_LABEL_UOM8"].ToString(), reader["IS_OUT_LABEL_UOM9"].ToString(), reader["IS_ACTIVE"].ToString(), reader["SYSTEM_CREATED"].ToString(), (byte[]) reader["TS"], reader["CREATED_BY"].ToString(), (reader["CREATED_DATE"].ToString() != "") ? DateTime.Parse(reader["CREATED_DATE"].ToString()) : new DateTime(), reader["UPDATED_BY"].ToString(), (reader["UPDATED_DATE"].ToString() != "") ? DateTime.Parse(reader["UPDATED_DATE"].ToString()) : new DateTime());
                }
            }
            return packInfo;
        }

        public PackInfo GetPackByID(DataBase dataBase, DbTransaction tran, string packID, string whLoginID)
        {
            string sql = this.SQL_SELECT_ALL_PACK.Replace("@_@", whLoginID) + " WHERE PACK_ID = @PACK_ID  ";
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@PACK_ID", packID) };
            PackInfo packInfo = null;
            IDataReader reader = dataBase.ExecuteReader(tran, CommandType.Text, sql, paras);
            if (reader.Read())
            {
                packInfo = new PackInfo((reader["ROWID"].ToString() != "") ? int.Parse(reader["ROWID"].ToString()) : 0, reader["WH_ID"].ToString(), reader["PACK_ID"].ToString(), reader["DESCRIPTION"].ToString(), reader["PACK_UOM1"].ToString(), (reader["QTY"].ToString() != "") ? float.Parse(reader["QTY"].ToString()) : 0f, (reader["LENGTH_UOM1"].ToString() != "") ? float.Parse(reader["LENGTH_UOM1"].ToString()) : 0f, (reader["WIDTH_UOM1"].ToString() != "") ? float.Parse(reader["WIDTH_UOM1"].ToString()) : 0f, (reader["HEIGHT_UOM1"].ToString() != "") ? float.Parse(reader["HEIGHT_UOM1"].ToString()) : 0f, (reader["CUBE_UOM1"].ToString() != "") ? float.Parse(reader["CUBE_UOM1"].ToString()) : 0f, reader["PACK_UOM2"].ToString(), (reader["INNER_PACK"].ToString() != "") ? float.Parse(reader["INNER_PACK"].ToString()) : 0f, (reader["LENGTH_UOM2"].ToString() != "") ? float.Parse(reader["LENGTH_UOM2"].ToString()) : 0f, (reader["WIDTH_UOM2"].ToString() != "") ? float.Parse(reader["WIDTH_UOM2"].ToString()) : 0f, (reader["HEIGHT_UOM2"].ToString() != "") ? float.Parse(reader["HEIGHT_UOM2"].ToString()) : 0f, (reader["CUBE_UOM2"].ToString() != "") ? float.Parse(reader["CUBE_UOM2"].ToString()) : 0f, reader["PACK_UOM3"].ToString(), (reader["CASE_CNT"].ToString() != "") ? float.Parse(reader["CASE_CNT"].ToString()) : 0f, (reader["LENGTH_UOM3"].ToString() != "") ? float.Parse(reader["LENGTH_UOM3"].ToString()) : 0f, (reader["WIDTH_UOM3"].ToString() != "") ? float.Parse(reader["WIDTH_UOM3"].ToString()) : 0f, (reader["HEIGHT_UOM3"].ToString() != "") ? float.Parse(reader["HEIGHT_UOM3"].ToString()) : 0f, (reader["CUBE_UOM3"].ToString() != "") ? float.Parse(reader["CUBE_UOM3"].ToString()) : 0f, reader["PACK_UOM4"].ToString(), (reader["PALLET"].ToString() != "") ? float.Parse(reader["PALLET"].ToString()) : 0f, (reader["LENGTH_UOM4"].ToString() != "") ? float.Parse(reader["LENGTH_UOM4"].ToString()) : 0f, (reader["WIDTH_UOM4"].ToString() != "") ? float.Parse(reader["WIDTH_UOM4"].ToString()) : 0f, (reader["HEIGHT_UOM4"].ToString() != "") ? float.Parse(reader["HEIGHT_UOM4"].ToString()) : 0f, (reader["CUBE_UOM4"].ToString() != "") ? float.Parse(reader["CUBE_UOM4"].ToString()) : 0f, (reader["PALLET_WOOD_LENGTH"].ToString() != "") ? float.Parse(reader["PALLET_WOOD_LENGTH"].ToString()) : 0f, (reader["PALLET_WOOD_WIDTH"].ToString() != "") ? float.Parse(reader["PALLET_WOOD_WIDTH"].ToString()) : 0f, (reader["PALLET_WOOD_HEIGHT"].ToString() != "") ? float.Parse(reader["PALLET_WOOD_HEIGHT"].ToString()) : 0f, (reader["PALLET_TI"].ToString() != "") ? decimal.Parse(reader["PALLET_TI"].ToString()) : 0M, (reader["PALLET_HI"].ToString() != "") ? decimal.Parse(reader["PALLET_HI"].ToString()) : 0M, reader["PACK_UOM5"].ToString(), (reader["CUBE"].ToString() != "") ? float.Parse(reader["CUBE"].ToString()) : 0f, reader["PACK_UOM6"].ToString(), (reader["GROSS_WGT"].ToString() != "") ? float.Parse(reader["GROSS_WGT"].ToString()) : 0f, reader["PACK_UOM7"].ToString(), (reader["NET_WGT"].ToString() != "") ? float.Parse(reader["NET_WGT"].ToString()) : 0f, reader["PACK_UOM8"].ToString(), (reader["OTHER_UNIT1"].ToString() != "") ? float.Parse(reader["OTHER_UNIT1"].ToString()) : 0f, (reader["LENGTH_UOM8"].ToString() != "") ? float.Parse(reader["LENGTH_UOM8"].ToString()) : 0f, (reader["WIDTH_UOM8"].ToString() != "") ? float.Parse(reader["WIDTH_UOM8"].ToString()) : 0f, (reader["HEIGHT_UOM8"].ToString() != "") ? float.Parse(reader["HEIGHT_UOM8"].ToString()) : 0f, reader["PACK_UOM9"].ToString(), (reader["OTHER_UNIT2"].ToString() != "") ? float.Parse(reader["OTHER_UNIT2"].ToString()) : 0f, (reader["LENGTH_UOM9"].ToString() != "") ? float.Parse(reader["LENGTH_UOM9"].ToString()) : 0f, (reader["WIDTH_UOM9"].ToString() != "") ? float.Parse(reader["WIDTH_UOM9"].ToString()) : 0f, (reader["HEIGHT_UOM9"].ToString() != "") ? float.Parse(reader["HEIGHT_UOM9"].ToString()) : 0f, reader["IS_CARTONIZE_UOM1"].ToString(), reader["IS_CARTONIZE_UOM2"].ToString(), reader["IS_CARTONIZE_UOM3"].ToString(), reader["IS_CARTONIZE_UOM4"].ToString(), reader["IS_CARTONIZE_UOM8"].ToString(), reader["IS_CARTONIZE_UOM9"].ToString(), reader["IS_REPLENISH_UOM1"].ToString(), reader["IS_REPLENISH_UOM2"].ToString(), reader["IS_REPLENISH_UOM3"].ToString(), reader["IS_REPLENISH_UOM4"].ToString(), reader["IS_REPLENISH_UOM8"].ToString(), reader["IS_REPLENISH_UOM9"].ToString(), reader["IS_IN_LABEL_UOM1"].ToString(), reader["IS_IN_LABEL_UOM2"].ToString(), reader["IS_IN_LABEL_UOM3"].ToString(), reader["IS_IN_LABEL_UOM4"].ToString(), reader["IS_IN_LABEL_UOM8"].ToString(), reader["IS_IN_LABEL_UOM9"].ToString(), reader["IS_OUT_LABEL_UOM1"].ToString(), reader["IS_OUT_LABEL_UOM2"].ToString(), reader["IS_OUT_LABEL_UOM3"].ToString(), reader["IS_OUT_LABEL_UOM4"].ToString(), reader["IS_OUT_LABEL_UOM8"].ToString(), reader["IS_OUT_LABEL_UOM9"].ToString(), reader["IS_ACTIVE"].ToString(), reader["SYSTEM_CREATED"].ToString(), (byte[]) reader["TS"], reader["CREATED_BY"].ToString(), (reader["CREATED_DATE"].ToString() != "") ? DateTime.Parse(reader["CREATED_DATE"].ToString()) : new DateTime(), reader["UPDATED_BY"].ToString(), (reader["UPDATED_DATE"].ToString() != "") ? DateTime.Parse(reader["UPDATED_DATE"].ToString()) : new DateTime());
            }
            if (!reader.IsClosed)
            {
                reader.Close();
            }
            return packInfo;
        }

        public DataSet GetPackByQueryList(List<string> sqlWhere, PackQueryEntity packQuery, string whLoginID)
        {
            string temp = this.SQL_SELECT_ALL_PACK.Replace("@_@", whLoginID);
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                if (i == 0)
                {
                    temp = temp + " WHERE " + sqlWhere[i].ToString();
                }
                else
                {
                    temp = temp + " AND " + sqlWhere[i].ToString();
                }
            }
            if (!packQuery.IsGetAll)
            {
                temp = PagingHelper.GetPagingSQL(temp, packQuery.CurrentPage, packQuery.PageSize, packQuery.SortField, packQuery.SortDirection);
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, temp);
        }

        public DataSet GetPackByQueryList(DataBase dataBase, DbTransaction tran, List<string> sqlWhere, PackQueryEntity packQuery, string whLoginID)
        {
            string temp = this.SQL_SELECT_ALL_PACK.Replace("@_@", whLoginID);
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                if (i == 0)
                {
                    temp = temp + " WHERE " + sqlWhere[i].ToString();
                }
                else
                {
                    temp = temp + " AND " + sqlWhere[i].ToString();
                }
            }
            if (!packQuery.IsGetAll)
            {
                temp = PagingHelper.GetPagingSQL(temp, packQuery.CurrentPage, packQuery.PageSize, packQuery.SortField, packQuery.SortDirection);
            }
            return dataBase.ExecuteDataSet(tran, CommandType.Text, temp);
        }

        public int InsertPack(PackInfo packInfo, List<string> whLoginID)
        {
            int result = 0;
            DataBase db = new DataBase();
            DbConnection conn = db.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    packInfo.WhID = whLoginID[i].Substring(0, whLoginID[i].Length - 1);
                    SqlParameter[] paras = this.Set_Pack_Parameters(packInfo);
                    if (paras != null)
                    {
                        result += db.ExecuteNonQuery(tran, CommandType.Text, this.SQL_INSERT_PACK.Replace("@_@", whLoginID[i]), paras);
                    }
                }
                tran.Commit();
            }
            catch (SqlException sqlEx)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return result;
        }

        public int InsertPack(DataBase dataBase, DbTransaction tran, PackInfo packInfo, List<string> whLoginID)
        {
            int result = 0;
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    packInfo.WhID = whLoginID[i].Substring(0, whLoginID[i].Length - 1);
                    SqlParameter[] paras = this.Set_Pack_Parameters(packInfo);
                    if (paras != null)
                    {
                        result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_INSERT_PACK.Replace("@_@", whLoginID[i]), paras);
                    }
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }

        private SqlParameter[] Set_Pack_Parameters(PackInfo packInfo)
        {
            SqlParameter[] paramArray = new SqlParameter[] { 
                new SqlParameter(this.WH_ID, SqlDbType.VarChar, 30), new SqlParameter(this.PACK_ID, SqlDbType.VarChar, 50), new SqlParameter(this.DESCRIPTION, SqlDbType.VarChar, 100), new SqlParameter(this.PACK_UOM1, SqlDbType.VarChar, 20), new SqlParameter(this.QTY, SqlDbType.Float, 13), new SqlParameter(this.LENGTH_UOM1, SqlDbType.Float, 8), new SqlParameter(this.WIDTH_UOM1, SqlDbType.Float, 8), new SqlParameter(this.HEIGHT_UOM1, SqlDbType.Float, 8), new SqlParameter(this.CUBE_UOM1, SqlDbType.Float, 8), new SqlParameter(this.PACK_UOM2, SqlDbType.VarChar, 20), new SqlParameter(this.INNER_PACK, SqlDbType.Float, 8), new SqlParameter(this.LENGTH_UOM2, SqlDbType.Float, 8), new SqlParameter(this.WIDTH_UOM2, SqlDbType.Float, 8), new SqlParameter(this.HEIGHT_UOM2, SqlDbType.Float, 8), new SqlParameter(this.CUBE_UOM2, SqlDbType.Float, 8), new SqlParameter(this.PACK_UOM3, SqlDbType.VarChar, 20), 
                new SqlParameter(this.CASE_CNT, SqlDbType.Float, 8), new SqlParameter(this.LENGTH_UOM3, SqlDbType.Float, 8), new SqlParameter(this.WIDTH_UOM3, SqlDbType.Float, 8), new SqlParameter(this.HEIGHT_UOM3, SqlDbType.Float, 8), new SqlParameter(this.CUBE_UOM3, SqlDbType.Float, 8), new SqlParameter(this.PACK_UOM4, SqlDbType.VarChar, 20), new SqlParameter(this.PALLET, SqlDbType.Float, 8), new SqlParameter(this.LENGTH_UOM4, SqlDbType.Float, 8), new SqlParameter(this.WIDTH_UOM4, SqlDbType.Float, 8), new SqlParameter(this.HEIGHT_UOM4, SqlDbType.Float, 8), new SqlParameter(this.CUBE_UOM4, SqlDbType.Float, 8), new SqlParameter(this.PALLET_WOOD_LENGTH, SqlDbType.Float, 8), new SqlParameter(this.PALLET_WOOD_WIDTH, SqlDbType.Float, 8), new SqlParameter(this.PALLET_WOOD_HEIGHT, SqlDbType.Float, 8), new SqlParameter(this.PALLET_TI, SqlDbType.Decimal, 13), new SqlParameter(this.PALLET_HI, SqlDbType.Decimal, 13), 
                new SqlParameter(this.PACK_UOM5, SqlDbType.VarChar, 20), new SqlParameter(this.CUBE, SqlDbType.Float, 8), new SqlParameter(this.PACK_UOM6, SqlDbType.VarChar, 20), new SqlParameter(this.GROSS_WGT, SqlDbType.Float, 8), new SqlParameter(this.PACK_UOM7, SqlDbType.VarChar, 20), new SqlParameter(this.NET_WGT, SqlDbType.Float, 8), new SqlParameter(this.PACK_UOM8, SqlDbType.VarChar, 20), new SqlParameter(this.OTHER_UNIT1, SqlDbType.Float, 8), new SqlParameter(this.LENGTH_UOM8, SqlDbType.Float, 8), new SqlParameter(this.WIDTH_UOM8, SqlDbType.Float, 8), new SqlParameter(this.HEIGHT_UOM8, SqlDbType.Float, 8), new SqlParameter(this.PACK_UOM9, SqlDbType.VarChar, 20), new SqlParameter(this.OTHER_UNIT2, SqlDbType.Float, 8), new SqlParameter(this.LENGTH_UOM9, SqlDbType.Float, 8), new SqlParameter(this.WIDTH_UOM9, SqlDbType.Float, 8), new SqlParameter(this.HEIGHT_UOM9, SqlDbType.Float, 8), 
                new SqlParameter(this.IS_CARTONIZE_UOM1, SqlDbType.VarChar, 1), new SqlParameter(this.IS_CARTONIZE_UOM2, SqlDbType.VarChar, 1), new SqlParameter(this.IS_CARTONIZE_UOM3, SqlDbType.VarChar, 1), new SqlParameter(this.IS_CARTONIZE_UOM4, SqlDbType.VarChar, 1), new SqlParameter(this.IS_CARTONIZE_UOM8, SqlDbType.VarChar, 1), new SqlParameter(this.IS_CARTONIZE_UOM9, SqlDbType.VarChar, 1), new SqlParameter(this.IS_REPLENISH_UOM1, SqlDbType.VarChar, 1), new SqlParameter(this.IS_REPLENISH_UOM2, SqlDbType.VarChar, 1), new SqlParameter(this.IS_REPLENISH_UOM3, SqlDbType.VarChar, 1), new SqlParameter(this.IS_REPLENISH_UOM4, SqlDbType.VarChar, 1), new SqlParameter(this.IS_REPLENISH_UOM8, SqlDbType.VarChar, 1), new SqlParameter(this.IS_REPLENISH_UOM9, SqlDbType.VarChar, 1), new SqlParameter(this.IS_IN_LABEL_UOM1, SqlDbType.VarChar, 1), new SqlParameter(this.IS_IN_LABEL_UOM2, SqlDbType.VarChar, 1), new SqlParameter(this.IS_IN_LABEL_UOM3, SqlDbType.VarChar, 1), new SqlParameter(this.IS_IN_LABEL_UOM4, SqlDbType.VarChar, 1), 
                new SqlParameter(this.IS_IN_LABEL_UOM8, SqlDbType.VarChar, 1), new SqlParameter(this.IS_IN_LABEL_UOM9, SqlDbType.VarChar, 1), new SqlParameter(this.IS_OUT_LABEL_UOM1, SqlDbType.VarChar, 1), new SqlParameter(this.IS_OUT_LABEL_UOM2, SqlDbType.VarChar, 1), new SqlParameter(this.IS_OUT_LABEL_UOM3, SqlDbType.VarChar, 1), new SqlParameter(this.IS_OUT_LABEL_UOM4, SqlDbType.VarChar, 1), new SqlParameter(this.IS_OUT_LABEL_UOM8, SqlDbType.VarChar, 1), new SqlParameter(this.IS_OUT_LABEL_UOM9, SqlDbType.VarChar, 1), new SqlParameter(this.IS_ACTIVE, SqlDbType.VarChar, 1), new SqlParameter(this.SYSTEM_CREATED, SqlDbType.VarChar, 1), new SqlParameter(this.CREATED_BY, SqlDbType.VarChar, 20), new SqlParameter(this.UPDATED_BY, SqlDbType.VarChar, 20)
             };
            if (!string.IsNullOrEmpty(packInfo.WhID))
            {
                paramArray[0].Value = packInfo.WhID;
            }
            else
            {
                paramArray[0].Value = DBNull.Value;
            }
            paramArray[1].Value = packInfo.PackID;
            paramArray[2].Value = packInfo.Description;
            paramArray[3].Value = packInfo.PackUom1;
            paramArray[4].Value = packInfo.Qty;
            paramArray[5].Value = packInfo.LengthUom1;
            paramArray[6].Value = packInfo.WidthUom1;
            paramArray[7].Value = packInfo.HeightUom1;
            paramArray[8].Value = packInfo.CubeUom1;
            paramArray[9].Value = packInfo.PackUom2;
            paramArray[10].Value = packInfo.InnerPack;
            paramArray[11].Value = packInfo.LengthUom2;
            paramArray[12].Value = packInfo.WidthUom2;
            paramArray[13].Value = packInfo.HeightUom2;
            paramArray[14].Value = packInfo.CubeUom2;
            paramArray[15].Value = packInfo.PackUom3;
            paramArray[0x10].Value = packInfo.CaseCnt;
            paramArray[0x11].Value = packInfo.LengthUom3;
            paramArray[0x12].Value = packInfo.WidthUom3;
            paramArray[0x13].Value = packInfo.HeightUom3;
            paramArray[20].Value = packInfo.CubeUom3;
            paramArray[0x15].Value = packInfo.PackUom4;
            paramArray[0x16].Value = packInfo.Pallet;
            paramArray[0x17].Value = packInfo.LengthUom4;
            paramArray[0x18].Value = packInfo.WidthUom4;
            paramArray[0x19].Value = packInfo.HeightUom4;
            paramArray[0x1a].Value = packInfo.CubeUom4;
            paramArray[0x1b].Value = packInfo.PalletWoodLength;
            paramArray[0x1c].Value = packInfo.PalletWoodWidth;
            paramArray[0x1d].Value = packInfo.PalletWoodHeight;
            paramArray[30].Value = packInfo.PalletTi;
            paramArray[0x1f].Value = packInfo.PalletHi;
            paramArray[0x20].Value = packInfo.PackUom5;
            paramArray[0x21].Value = packInfo.Cube;
            paramArray[0x22].Value = packInfo.PackUom6;
            paramArray[0x23].Value = packInfo.GrossWgt;
            paramArray[0x24].Value = packInfo.PackUom7;
            paramArray[0x25].Value = packInfo.NetWgt;
            if (!string.IsNullOrEmpty(packInfo.PackUom8))
            {
                paramArray[0x26].Value = packInfo.PackUom8;
            }
            else
            {
                paramArray[0x26].Value = DBNull.Value;
            }
            paramArray[0x27].Value = packInfo.OtherUnit1;
            paramArray[40].Value = packInfo.LengthUom8;
            paramArray[0x29].Value = packInfo.WidthUom8;
            paramArray[0x2a].Value = packInfo.HeightUom8;
            paramArray[0x2b].Value = packInfo.PackUom9;
            paramArray[0x2c].Value = packInfo.OtherUnit2;
            paramArray[0x2d].Value = packInfo.LengthUom9;
            paramArray[0x2e].Value = packInfo.WidthUom9;
            paramArray[0x2f].Value = packInfo.HeightUom9;
            paramArray[0x30].Value = packInfo.IsCartonizeUom1;
            paramArray[0x31].Value = packInfo.IsCartonizeUom2;
            paramArray[50].Value = packInfo.IsCartonizeUom3;
            paramArray[0x33].Value = packInfo.IsCartonizeUom4;
            paramArray[0x34].Value = packInfo.IsCartonizeUom8;
            paramArray[0x35].Value = packInfo.IsCartonizeUom9;
            paramArray[0x36].Value = packInfo.IsReplenishUom1;
            paramArray[0x37].Value = packInfo.IsReplenishUom2;
            paramArray[0x38].Value = packInfo.IsReplenishUom3;
            paramArray[0x39].Value = packInfo.IsReplenishUom4;
            paramArray[0x3a].Value = packInfo.IsReplenishUom8;
            paramArray[0x3b].Value = packInfo.IsReplenishUom9;
            paramArray[60].Value = packInfo.IsInLabelUom1;
            paramArray[0x3d].Value = packInfo.IsInLabelUom2;
            paramArray[0x3e].Value = packInfo.IsInLabelUom3;
            paramArray[0x3f].Value = packInfo.IsInLabelUom4;
            paramArray[0x40].Value = packInfo.IsInLabelUom8;
            paramArray[0x41].Value = packInfo.IsInLabelUom9;
            paramArray[0x42].Value = packInfo.IsOutLabelUom1;
            paramArray[0x43].Value = packInfo.IsOutLabelUom2;
            paramArray[0x44].Value = packInfo.IsOutLabelUom3;
            paramArray[0x45].Value = packInfo.IsOutLabelUom4;
            paramArray[70].Value = packInfo.IsOutLabelUom8;
            paramArray[0x47].Value = packInfo.IsOutLabelUom9;
            paramArray[0x48].Value = packInfo.IsActive;
            paramArray[0x49].Value = packInfo.SystemCreated;
            paramArray[0x4a].Value = packInfo.CreatedBy;
            paramArray[0x4b].Value = packInfo.UpdatedBy;
            return paramArray;
        }

        public int UpdatePack(PackInfo packInfo, List<string> whLoginID)
        {
            int result = 0;
            DataBase db = new DataBase();
            DbConnection conn = db.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    packInfo.WhID = whLoginID[i].Substring(0, whLoginID[i].Length - 1);
                    SqlParameter[] paras = this.Set_Pack_Parameters(packInfo);
                    if (paras != null)
                    {
                        result += db.ExecuteNonQuery(tran, CommandType.Text, this.SQL_UPDATE_PACK.Replace("@_@", whLoginID[i]), paras);
                    }
                }
                tran.Commit();
            }
            catch (SqlException sqlEx)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return result;
        }

        public int UpdatePack(DataBase dataBase, DbTransaction tran, PackInfo packInfo, List<string> whLoginID)
        {
            int result = 0;
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    packInfo.WhID = whLoginID[i].Substring(0, whLoginID[i].Length - 1);
                    SqlParameter[] paras = this.Set_Pack_Parameters(packInfo);
                    if (paras != null)
                    {
                        result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_UPDATE_PACK.Replace("@_@", whLoginID[i]), paras);
                    }
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }
    }
}

